﻿<?php

$socket = "";


//=============================================================================

set_time_limit(0);
//$host="192.168.100.236";
$host = '127.0.0.1';
$port=5432;

//创建一个socket
$socket=socket_create(AF_INET,SOCK_STREAM,SOL_TCP)or die("cannot create socket\n");
//进行接口连接
$conn=socket_connect($socket,$host,$port) or die("cannot connect server\n");
if($conn){echo "client connect ok!";}
//向接口写数据
socket_write($socket,"NMC:6;7,4,8#") or die("cannot write data\n");
//socket_write($socket,"NAC:1&2&3&4&5&6&7&8&9&10&11&12&13#") or die("cannot write data\n");
//$buffer=socket_read($socket,1024,PHP_NORMAL_READ);
//if($buffer){
//	echo "response was:".$buffer."\n";
//}
//关闭接口
socket_close($socket);


$build_temp;
$build_temp['a'] = array('7.4','7.11','7.8','8.4','8.5','8.12','8.15','9.6','12.3','9.15','10.9','11.1','11.6','11.7','11.16','12.7','12.12','6.7');
$build_temp['b'] = array('7.2','7.12','7.10','8.3','8.7','8.14','9.2','9.4','12.5','10.3','10.10','10.14','11.3','11.11','11.13','12.9','12.13','6.9');
$build_temp['c'] = array('7.3','7.13','7.6','8.2','8.8','8.13','9.1','9.5','12.4','9.16','10.8','10.15','11.4','11.10','11.14','12.10','12.15','6.4');
$build_temp['d'] = array('7.5','7.14','7.7','7.16','8.6','8.10','8.16','9.8','12.1','10.4','10.12','10.16','11.2','11.8','11.12','12.6','12.11','6.8');
$build_temp['e'] = array('7.1','7.15','7.9','8.1','8.9','8.11','9.3','9.7','12.2','10.6','10.11','10.13','11.5','11.9','11.15','12.8','12.14',6.6);






class test{
	//初始化socket
	function initSocket(){
		set_time_limit(0);
		$host="192.168.100.236";
		$host = '127.0.0.1';
		$port=5432;

		//创建一个socket
		$socket=socket_create(AF_INET,SOCK_STREAM,SOL_TCP)or die("cannot create socket\n");
		$conn=socket_connect($socket,$host,$port) or die("cannot connect server\n");

		if($conn){
			return true;
		}else{
			return false;
		}

	}

	//控制
	function basicControl($msg){
		//命令 comm
		//板子 plane
		//路数 no
		//NMC:6;7,4,8#
		if(initSocket()){
			socket_write($socket,$msg) or die("cannot write data\n");
			closeSocket();
		}else{
			echo "please retry";
		}

	}

	function closeSocket(){
		socket_close($socket);
	}


	//单个开
	//param 板子号  路数（号） 命令
	public function singleOn(){
		if(initSocket()){
			$msg = "";
			basicControl($msg);

			closeSocket();
		}else{
			echo "please retry";
		}

	}



	//单个关
	//param 板子号  路数（号） 命令

$msg = "NC:1;16#";
// 	//多个开
// 	//param 板子号（多个）  路数（号） 命令
$msg = "NMO:1;2,3,4,5#";
// 	//多个关
// 	//param 板子号（多个）  路数（号） 命令
$msg = "NMC:1;2,3,4,5#";
// 	//全开
// 	//param 板子号（多个）  命令
$msg = "NAO:1&2&3#(2,3,4)";
// 	//全关
// 	//param 板子号（多个）  命令
$msg = "NAC:1&2&3#(1-16)";
}




?>
